import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/common/app.dart';
import 'package:flutter_smart_heating/config/config.dart';
import 'package:flutter_smart_heating/ui/ui.dart';

class SettingAboutPage extends StatefulWidget {
  const SettingAboutPage({super.key});

  @override
  State<SettingAboutPage> createState() => _SettingAboutPageState();
}

class _SettingAboutPageState extends State<SettingAboutPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        actions: const [UiRightMenuButtonGroup()],
      ),
      body: ListView(
        padding: const EdgeInsets.all(UiTheme.spacingXX),
        children: [
          const SizedBox(height: 50),
          Center(
            child: Column(
              children: [
                Container(
                  width: 100,
                  height: 100,
                  decoration: BoxDecoration(
                    color: UiTheme.primary,
                    borderRadius: BorderRadius.circular(UiTheme.boxRadiusX * 2),
                  ),
                  child: ZoomIn(
                    delay: const Duration(milliseconds: 200),
                    child: Image.asset(
                      'res/images/launcher_icon_round.png',
                      width: 100,
                    ),
                  ),
                ),
                const SizedBox(height: 20),
                const Text(
                  Config.appName,
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 10),
                const Text('v${Config.appVersion}'),
              ],
            ),
          ),
          const SizedBox(height: 50),
          UiPanel(
            children: [
              cell(
                icon: UiIcons.info_circle,
                title: '关于我们',
                onTap: () {
                  App.push(
                    'browser://plugin/page/index/detail.html?name=aboutus&title=关于我们',
                  );
                },
              ),
              cell(
                icon: UiIcons.user,
                title: '用户协议',
                onTap: () {
                  App.push(
                    'browser://plugin/page/index/detail.html?name=agreement&title=用户协议',
                  );
                },
              ),
              cell(
                icon: UiIcons.safetycertificate,
                title: '隐私政策',
                onTap: () {
                  App.push(
                      'browser://plugin/page/index/detail.html?name=policy&title=隐私政策');
                },
              ),
            ],
          ),
          const UiLineBreak(),
          UiPanel(
            children: [
              cell(
                icon: Icons.refresh,
                title: '检查更新',
                showDivider: false,
              ),
            ],
          )
        ],
      ),
    );
  }

  Widget cell({
    required IconData icon,
    required String title,
    Function()? onTap,
    bool showDivider = true,
    Widget? trailing,
  }) {
    return UiListCell(
      onTap: onTap,
      leading: UiLinearGradientMask(
          child: Icon(
        icon,
        color: Colors.white,
      )),
      leadingSpace: 10,
      title: Text(title),
      showArrow: true,
      showDivider: showDivider,
      dividerIndent: 50,
      trailing: trailing,
      backgroundColor: Colors.transparent,
    );
  }
}
